package com.pengshun.modules.api.petrol;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.petrol.service.JyPetrolStationOrderService;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationOrderDto;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationProductListDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.JyPetrolStationProduct;
import com.pengshun.modules.domain.JyPetrolStationReal;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/6/28
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "加油商户管理")
@RequestMapping("/api/petrol/merchant")
public class PetrolStationMerChantController {

    private final JyPetrolStationOrderService orderService;


    @ApiOperation(value = "加油列表")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "updateBy", value = " 名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "carOwnerNum", value = " 车牌号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationOrderDto.class)
    })
    @Authorization
    public BaseResult merchantOrderList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) PagePara page, JyPetrolStationOrderDto para) {
        BaseResult res = orderService.merchantOrderList(page, para,user.getId());
        return res;
    }


    @ApiOperation(value = "订单更新")
    @PostMapping(value = "/order-update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "petrolStationOrderId", value = "加油站订单id", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @Authorization
    public BaseResult orderUpdate(@ApiIgnore @CurrUserInfo User user,Long petrolStationOrderId) throws Exception {
        BaseResult res = orderService.orderUpdate(user.getId(),petrolStationOrderId);
        return res;
    }
    @ApiOperation(value = "营业状态更新")
    @PostMapping(value = "/station-update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cooperateState", value = "0不合作 1合作中", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @Authorization
    public BaseResult stationUpdate(@ApiIgnore @CurrUserInfo User user,Integer cooperateState) throws Exception {
        BaseResult res = orderService.stationUpdate(user.getId(),cooperateState);
        return res;
    }


    @ApiOperation(value = "加油站详情")
    @GetMapping (value = "/station-detil")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @Authorization
    public BaseResult stationDetil(@ApiIgnore @CurrUserInfo User user) throws Exception {
        BaseResult res = orderService.stationDetil(user.getId());
        return res;
    }

    @ApiOperation(value = "油气列表")
    @GetMapping (value = "/product-list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationProduct.class)
    })
    @Authorization
    public BaseResult productList(@ApiIgnore @CurrUserInfo User user) throws Exception {
        BaseResult res = orderService.productList(user.getId());
        return res;
    }

    @ApiOperation(value = "油气价格更新")
    @GetMapping (value = "/product-uddate")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
            @ApiImplicitParam(name = "petrolStationProductId", value = "商品id", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "stationPrice", value = "油站价格", dataType = "double",required = true, paramType = "query"),
    })
    @Authorization
    public BaseResult productUddate(@ApiIgnore @CurrUserInfo User user,@ApiIgnore JyPetrolStationProduct para) throws Exception {
        BaseResult res = orderService.productUddate(user.getId(),para);
        return res;
    }

    @ApiOperation(value = "企业认证")
    @GetMapping (value = "/station-real")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @Authorization
    public BaseResult stationReal(@ApiIgnore @CurrUserInfo User user, JyPetrolStationReal para) throws Exception {
        BaseResult res = orderService.stationReal(user.getId(),para);
        return res;
    }


    @ApiOperation(value = "收款订单二维码生成")
    @PostMapping(value = "/qrcode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "petrolStationGunId", value = "加油站枪号id", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "stationNum", value = "加油油量", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "discountsAmount", value = "优惠金额", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "realAmount", value = "实付金额", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "stationAmount", value = "加油金额", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @Authorization
    public BaseResult qrcode(@ApiIgnore @CurrUserInfo User user,@ApiIgnore JyPetrolStationOrderDto para) throws Exception {
        BaseResult res = orderService.qrcode(user.getId(),para);
        return res;
    }

}
